home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
tools
/
c2latex.lha
/
c++2latex
/
c++2latex.l
< prev
next >
Wrap
Text File
|
1993-08-08
|
8KB
|
332 lines
*
* This is a flex input file but should be edited in -*-C-*- mode
*
* C++2LaTeX: Produce prettyprinted LaTeX files from C++ or C sources.
* Copyright (C) 1990 Norbert Kiesel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Norbert Kiesel
* RWTH Aachen / Institut f. Informatik III
* Ahornstr. 55
* D-5100 Aachen
* West Germany
*
* Phone: +49 241 80-7266
* EUNET: norbert@rwthi3.uucp
* USENET: ...!mcvax!unido!rwthi3!norbert
* X.400: norbert@rwthi3.informatik.rwth-aachen.de
*
* Please contact me for any bugs you find in this code or any
* improvements! I'd also be very happy to get feedback where and
* how frequently this program is used (just drop a little mail :-).
*
* ---------------------------------------------------------------------
*
* C++2LaTeX 2.0:
* Produce even more prettyprinted LaTeX files from C++ or C sources.
*
* Copyright (C) 1991 Joerg Heitkoetter
* Systems Analysis Group, University of Dortmund, Germany.
* (heitkoet@gorbi.informatik.uni-dortmund.de).
*
*/
x STRING BCOMMENT INCLUDE SLASHCOMMENT
s CPLUSPLUS
{
define KEY printf ("{\\%s %s}", keyword_font, yytext)
define CPP printf ("{\\%s \\%s}", cpp_font, yytext)
define SYM(x) printf ("$\\%s$", x)
define OUT(x) printf ("%s", x)
define BTAB printf ("\\hspace*{%d\\indentation}", tabtobrace)
define CTAB printf ("\\hspace*{%d\\indentation}", tabtocomment)
define FONT(x) printf ("{\\%s ",x);
define SUB(x) substitute(x)
define IND indent(yytext)
define INIT BEGIN (cplusplus_mode ? CPLUSPLUS : INITIAL);
define REPARSE yyless (0)
include <stdio.h>
ifdef ANSI_C
#ifdef C_PLUSPLUS
#error ANSI_C and C_PLUSPLUS are mutually exclusive
#else
int cplusplus_mode = 0;
#endif
else /* CPLUSPLUS or default */
int cplusplus_mode = 1;
endif
nt complete_file = 0;
nt header = 0;
nt tabtotab = 8;
nt piped = 0;
nt aligntoright = 1; /* align comments to the right -joke */
nt tabtobrace = 2; /* distance between closing brace and corresponding comment -joke */
nt tabtocomment = 4; /* distance between statement and corresponding comment -joke */
har *font_size = "10"; /* used to be 11 -joke */
har *indentation = "0.5em";
har *comment_font = "it";
har *keyword_font = "bf";
har *header_font = "sl";
har *cpp_font = "tt";
har *string_font = "tt";
ifdef __STDC__
oid substitute(const char *);
oid indent(const char *);
oid newpage(int);
oid usage(const char *);
else
oid substitute();
oid indent();
oid newpage();
oid usage();
endif
}
%
INIT;
#"[ \t]*"include" { CPP; BEGIN (INCLUDE); }
#"[ \t]*"define" |
#"[ \t]*"undef" |
#"[ \t]*"pragma" |
#"[ \t]*"if" |
#"[ \t]*"ifdef" |
#"[ \t]*"ifndef" |
#"[ \t]*"elif" |
#"[ \t]*"else" |
#"[ \t]*"error" |
#"[ \t]*"line" | /* added G++ special #line directive -joke */
#"[ \t]*"ex" | /* added G++ special #ex directive -joke */
#"[ \t]*"endif" CPP;
INCLUDE>"<"[^>]*/">" { OUT ("$<$"); FONT (string_font);
SUB (yytext+1); OUT ("}$>$");
input(); INIT; }
INCLUDE>\"[^\"]*/\" { OUT ("\""); FONT (string_font);
SUB (yytext+1); OUT ("}\"");
input(); INIT; }
INCLUDE>[ \t]+ ECHO;
INCLUDE>[\n] OUT ("\\mbox{}\\\\\n");
INCLUDE>. { REPARSE; INIT; }
auto" |
double" |
int" |
struct" |
break" |
else" |
long" |
switch" |
case" |
enum" |
register" |
typedef" |
char" |
extern" |
return" |
union" |
const" |
float" |
short" |
unsigned" |
continue" |
for" |
signed" |
void" |
default" |
goto" |
sizeof" |
volatile" |
do" |
if" |
static" |
while" |
CPLUSPLUS>"new" |
CPLUSPLUS>"delete" |
CPLUSPLUS>"this" |
CPLUSPLUS>"operator" |
CPLUSPLUS>"class" |
CPLUSPLUS>"public" |
CPLUSPLUS>"protected" |
CPLUSPLUS>"private" |
CPLUSPLUS>"virtual" |
CPLUSPLUS>"friend" |
CPLUSPLUS>"inline" |
CPLUSPLUS>"dynamic" | /* added -joke */
CPLUSPLUS>"typeof" | /* added -joke */
CPLUSPLUS>"all" | /* G++ special added -joke */
CPLUSPLUS>"except" | /* G++ special added -joke */
CPLUSPLUS>"exception" | /* G++ special added -joke */
CPLUSPLUS>"raise" | /* G++ special added -joke */
CPLUSPLUS>"raises" | /* G++ special added -joke */
CPLUSPLUS>"reraise" | /* G++ special added -joke */
CPLUSPLUS>"try" | /* G++ special added -joke */
CPLUSPLUS>"asm" | /* added -joke */
CPLUSPLUS>"catch" | /* added -joke */
CPLUSPLUS>"overload" KEY;
->" SYM ("rightarrow");
<<" SYM ("ll");
>>" SYM ("gg");
<=" SYM ("leq");
>=" SYM ("geq");
!=" SYM ("neq");
||" SYM ("mid\\mid");
..." SYM ("ldots");
*=" SYM ("ast=");
<<=" SYM ("ll=");
>>=" SYM ("gg=");
^=" SYM ("vee=");
|=" SYM ("mid=");
~" SYM ("sim");
*" SYM ("ast");
^" SYM ("wedge");
|" SYM ("mid");
CPLUSPLUS>"->*" SYM ("rightarrow\\ast");
/" OUT ("$/$");
<" OUT ("$<$");
>" OUT ("$>$");
&&" OUT ("\\&\\&");
%=" OUT ("\\%=");
&=" OUT ("\\&=");
{" OUT ("\\{");
}" OUT ("\\}");
&" OUT ("\\&");
%" OUT ("\\%");
--" OUT ("-{}-");
CPLUSPLUS>".*" OUT (".$\\ast$");
?" |
:" |
=" |
," |
." |
;" |
!" |
-" |
+" |
/=" |
==" |
++" |
+=" |
-=" |
(" |
)" |
[" |
]" |
CPLUSPLUS>"::" ECHO;
CPLUSPLUS>[a-zA-Z_$][a-zA-Z_$0-9]* |
a-zA-Z_][a-zA-Z_0-9]* SUB (yytext);
/* 1. Asterisk comments mini scanner */
/* 1.1. Curly brace comment */
}"[ \t]*"/*" { BEGIN (BCOMMENT);
OUT ("\\}");
BTAB;
FONT (comment_font);
OUT ("/$\\ast$"); }
/* 1.2. Comments at the beginning of a line */
[ \t]*"/*" { BEGIN (BCOMMENT);
FONT (comment_font);
REPARSE; }
/* 1.3. Other comments, aligned to right side of paper */
/*" { BEGIN (BCOMMENT);
if (aligntoright) {
OUT ("\\hfill");
} else {
CTAB;
}
FONT (comment_font);
OUT ("/$\\ast$"); }
BCOMMENT>"*/" { INIT; OUT ("$\\ast$/}"); }
BCOMMENT>"\n" OUT ("\\mbox{}\\\\\n");
BCOMMENT>[ \t]+ IND;
BCOMMENT>. SUB (yytext);
/* 2. Double slash ``//'' comments mini scanner */
/* 2.1. Curly brace comment */
CPLUSPLUS>}[ \t]*"//" { BEGIN (SLASHCOMMENT);
OUT ("\\}");
BTAB;
FONT (comment_font);
OUT ("//");}
/* 2.2. Complete line comment */
CPLUSPLUS>^[ \t]*"//" { BEGIN (SLASHCOMMENT);
FONT (comment_font);
REPARSE; }
/* 2.3. Other comments */
CPLUSPLUS>"//" { BEGIN (SLASHCOMMENT);
if (aligntoright) {
OUT ("\\hfill");
} else {
CTAB;
}
FONT (comment_font);
OUT ("//"); }
SLASHCOMMENT>"\n" { INIT; OUT ("}\\mbox{}\\\\\n"); }
SLASHCOMMENT>[ \t]+ IND;
SLASHCOMMENT>. SUB (yytext);
?\" { BEGIN (STRING);
FONT (string_font); OUT ("\""); }
STRING>\\\\ OUT ("$\\backslash\\backslash$");
STRING>\\[bfnrtv'"] { OUT ("$\\backslash$"); SUB (yytext+1); }
STRING>\" { INIT; OUT ("\"}"); }
STRING>"\n" OUT ("\\mbox{}\\\\\n");
STRING>^[ \t]+ IND;
STRING>. SUB (yytext);
[0-9]*\.[0-9]+[fFlL]?) |
[0-9]+\.[0-9]*[fFlL]?) |
[0-9]*\.?[0-9]+[eE][+-]?[0-9]+) |
[0-9]+\.?[0-9]*[eE][+-]?[0-9]+) ECHO;
0-9]+[uUlL]? ECHO;
?'[ -~]' |
?'\\[ntvbrfa\\?'"]' |
?'\\[0-7]{1,3}' |
?'\\x[0-9a-fA-F]{1,2}' SUB (yytext);
[0-7]+[uUlL]? ECHO;
x[0-9a-fA-F]+[uUlL]? ECHO;
\\\n" OUT ("$\\backslash$\\\\\n");
[ \t]+ IND;
\t]+ ECHO;
\f"[\n]? OUT ("\\newpage\n");
\n" OUT ("\\mbox{}\\\\\n");
%
include "main.c"